package com.lanyou.esb.cook.proxy.common;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 日期帮助类
 * 
 * @author Davey.wu
 */
public final class DateUtils {
	/** 获取日期，格式为：yyyyMMddHHmmss.SSS **/
	public static final SimpleDateFormat DATEPATTERN_YYYYMMDDHHMMssSSS = new SimpleDateFormat(
			"yyyy-MM-dd HH:mm:ss.SSS");
	/** 获取日期，格式为：yyyyMMddHHmmss **/
	public static final SimpleDateFormat DATEPATTERN_YYYYMMDDHHMMSS = new SimpleDateFormat(
			"yyyyMMddHHmmss");
	/** 获取日期，格式为：yyyyMMddHHmm **/
	public static final SimpleDateFormat DATEPATTERN_YYYYMMDDHHMM = new SimpleDateFormat(
			"yyyyMMddHHmm");
	/** 获取日期，格式为：yyyyMMddHH **/
	public static final SimpleDateFormat DATEPATTERN_YYYYMMDDHH = new SimpleDateFormat(
			"yyyyMMddHH");
	/** 获取日期，格式为：yyyyMMdd **/
	public static final SimpleDateFormat DATEPATTERN_YYYYMMDD = new SimpleDateFormat(
			"yyyyMMdd");
	/** 获取日期，格式为：yyyyMM **/
	public static final SimpleDateFormat DATEPATTERN_YYYYMM = new SimpleDateFormat(
			"yyyyMM");

	/** 获取日期，格式为：yyyy **/
	public static final SimpleDateFormat DATEPATTERN_YEAR = new SimpleDateFormat(
			"yyyy");
	/** 获取日期，格式为：MM **/
	public static final SimpleDateFormat DATEPATTERN_MONTH = new SimpleDateFormat(
			"MM");
	/** 获取日期，格式为：dd **/
	public static final SimpleDateFormat DATEPATTERN_DAY = new SimpleDateFormat(
			"dd");
	/** 获取日期，格式为：HH **/
	public static final SimpleDateFormat DATEPATTERN_HOUR = new SimpleDateFormat(
			"HH");
	/** 获取日期，格式为：mm **/
	public static final SimpleDateFormat DATEPATTERN_MINUTE = new SimpleDateFormat(
			"mm");
	/** 获取日期，格式为：ss **/
	public static final SimpleDateFormat DATEPATTERN_SECOND = new SimpleDateFormat(
			"ss");

	/**
	 * 判断是否是同一天
	 * 
	 * @param date1
	 *            ：日期1
	 * @param date2
	 *            ：日期2
	 * @return
	 */
	public static boolean isSameDay(Date date1, Date date2) {
		if (date1 == null || date2 == null) {
			return false;
		}
		Calendar calendar1 = Calendar.getInstance();
		calendar1.setTime(date1);

		Calendar calendar2 = Calendar.getInstance();
		calendar2.setTime(date2);

		return calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR)
				&& calendar1.get(Calendar.MONTH) == calendar2
						.get(Calendar.MONTH)
				&& calendar1.get(Calendar.DAY_OF_MONTH) == calendar2
						.get(Calendar.DAY_OF_MONTH);
	}

	public static boolean after(Date start, int period, Date end) {
		if (start == null || end == null || period <= 0) {
			return false;
		}
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(start);
		calendar.add(Calendar.SECOND, period);
		return calendar.getTime().after(end);
	}
	//
	// public static void main(String[] args) {
	// Date start =new Date();
	// Date end=new Date();
	// Calendar calendar=Calendar.getInstance();
	// calendar.setTime(start);
	// calendar.add(Calendar.SECOND, -100);
	// System.out.println(start);
	// System.out.println(calendar.getTime());
	// System.out.println(after(calendar.getTime(),120,end));
	// }
}
